package com.yvon.maple.service.msg.core.handler.handler;

import com.yvon.maple.service.msg.core.common.domain.TaskInfo;
import com.yvon.maple.service.msg.core.model.entity.ImContent;
import com.yvon.maple.service.msg.core.common.enums.ChannelType;
import com.yvon.maple.service.msg.core.common.model.content.ImContentModel;
import com.yvon.maple.service.msg.core.service.ImContentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author : Yvon
 * @since : 2021-12-28
 */
@Slf4j
@Component
public class IMHandler extends Handler{

    @Autowired
    private ImContentService imContentService;

    public IMHandler() {
        channelCode = ChannelType.IM.getCode();
    }

    @Override
    public void handler(TaskInfo taskInfo) {
        ImContentModel contentModel = (ImContentModel) taskInfo.getContentModel();


        ImContent message = ImContent.builder().content(contentModel.getContent()).title(contentModel.getTitle()).build();
        imContentService.send(message, taskInfo.getReceiver());
    }


}
